package writtenTraining.day35;

import java.util.*;

/**
 * day35:(1)模拟+找规律：MT8 奇数位丢弃
 */

 class Main1 {
    public static void main(String[] args) {
        // 模拟 + 找规律
        // 输入数据
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            int n = in.nextInt();
            int num = 1;
            while((num - 1) <= n) {
                num *= 2;
            }
            // 遍历走完最后一位就是最大值

            // 输出数据
            // 获取最后一位
            System.out.println(num / 2 - 1);
        }

    }
}


/**
 * day35:(2)dfs:求和
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static int n , m ;
    public static List<Integer> tmp;
    public static List<List<Integer>> ret;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();m = in.nextInt();
        tmp = new ArrayList<>();
        ret = new ArrayList<>();

        dfs(0, 0);

        for(List<Integer> list : ret) {
            for(int i = 0; i < list.size() - 1; i++) {
                System.out.print(list.get(i) + " ");
            }
            System.out.println(list.get(list.size() - 1));
        }
    }

    public static void dfs(int num , int sum) {
        if(sum == m) {
            ret.add(new ArrayList<>(tmp));
            return;
        }

        for(int i = num + 1; i <= n; i++) {
            if(sum < m) {
                tmp.add(i);
                dfs(i,sum + i);
                tmp.remove(tmp.size() - 1);
            }
        }

    }
}

/**
 * day35:(3)动态规划+ 字符串：HJ52 计算字符串的编辑距离
 */

 class Main3 {
    public static void main(String[] args) {
        // 动态规划
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            char[] str1 = in.next().toCharArray(),
                    str2 = in.next().toCharArray();

            int len1 = str1.length, len2 = str2.length;
            // 创建dp
            int[][] dp =new int[len1 + 1][len2 + 1];

            int ret = -0x3f3f3f3f;
            // 初始化
            for(int i =0; i <= len1; i++) {
                dp[i][0] = i;
            }

            for(int j =0; j <= len2;j++) {
                dp[0][j] = j;
            }

            for(int i = 1; i <= len1; i++) {
                for(int j = 1; j <= len2; j++) {
                    if(str1[i - 1] == str2[j - 1]) {
                        dp[i][j] = dp[i-1][j-1] ;
                    } else {
                        dp[i][j] = Math.min(dp[i-1][j], Math.min(dp[i][j-1],dp[i-1][j-1])) + 1;
                    }
                }
            }


            System.out.println(dp[len1][len2]);
        }

    }
}